import $ from '../common';
Page({
  data: {
    titleHeight: $.gData().titleHeight,
    statuHeight: $.gData().statuHeight,
    // isIphoneX:$.gData().isIphoneX,
    code: '',
    password: '',
    countdown: 60,
    disabledCode: true,
    isfirst: true
  },
  bindKeyInput(e) { //code输入
    this.setData({
      code: e.detail.value
    })
  },
  bindpasswordInput(e) { //密码输入
    this.setData({
      password: e.detail.value
    })
  },
  clearcode() { //清除验证码
    this.setData({
      code: ''
    })
  },
  getcode() {
    let countdown = this.data.countdown
    this.setData({
      isfirst: false
    })
    let _fn = () => {
      if (countdown == 0) {
        this.resetDentify()
      } else {
        this.disabledCode = false
        this.setData({
          countdown: countdown,
          disabledCode: this.disabledCode,

        })
        if (countdown == 60) {
          // this.getcodehand()
        }
        countdown--
      }
    }
    _fn()
    this.setTimeDentify = setInterval(() => {
      _fn()
    }, 1000)
  },
  getcodehand() { //获取验证码的请求
    // $.get("/verifycode", {
    //   phone: this.data.phone,
    //   type: 'RESET'
    // }, (data) => {
    //   $.tip("验证码已发送到尾号为" + (this.data.phone).replace(/\s/g, "").toString().substring(7) + "的手机上，请注意查收!")
    // }, (res) => {
    //   $.tip(res.message)
    //   this.resetDentify()
    // })
  },
  resetDentify() { //当60s结束后
    clearInterval(this.setTimeDentify)
    this.disabledCode = true
    this.countdown = 60
    this.setData({
      countdown: this.countdown,
      disabledCode: this.disabledCode
    })
  },
  submit() { //提交
    const {code,password} = this.data
    if (!code) {
      $.tip('请先输入验证码')
      return
    }
    if (!password) {
      $.tip('请先输入新密码')
      return
    }
    $.post('/user/passwd/reset', {
      verify:code,
      passwd:password
    }, res => {
      console.log(res);
    })
  },
  onLoad(e) {
    this.setData({
      phone: e.phone
    })
  },
  onShow() {},
})